﻿using System;
using System.Configuration;
using System.Data;
using System.Collections.Generic;
using KPIS.DBM;

namespace KPIS.GERP.GBMS.MODEL
{
    public static class SystemInfo
    {
        private static string connectionString = ConfigurationSettings.AppSettings["ConnectionString"];// "server=10.8.99.71;user id=root;pwd=root123456789;database=gerp_itpf";
        private static DataProvider provider = DataProvider.SqlServer;

        private static string deleteRecordStatus = "D";
        private static string processRecordStatus = "P";
        private static string approveRecordStatus = "A";
        private static string workRecordStatus = "W";
        private static string cancelRecordStatus = "C";
        private static string activeRecordStatus = "U";
        private static string rejectStatus = "R";
        private static int currentYear = GetCurrentYear();
        private static int currentYearReq = GetCurrentYearRequest();

        private static int GetCurrentYear()
        {
	        DataTable dtb = new DataTable();
			try
			{
				IDBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);
				dbManager.CreateParameters(1);
				dbManager.AddParameters(0, "@bgm_sys_control_name", "bg_year");
				string strSQL = " select bgm_sys_control_values "
								+ " from bgm_system_control"
								+ " where bgm_sys_control_name=@bgm_sys_control_name";

				dbManager.Open();
				dtb = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0];
				dbManager.Dispose();
				return Convert.ToInt32(dtb.Rows[0][0]);
			}
			catch (Exception error)
			{
				return -1;
			}
        }

        private static int GetCurrentYearRequest()
        {
			DataTable dtb = new DataTable();
			try{
				IDBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);
				dbManager.CreateParameters(1);
				dbManager.AddParameters(0, "@bgm_sys_control_name", "req_bg_year");
				string strSQL = " select bgm_sys_control_values "
						   + " from bgm_system_control"
						   + " where bgm_sys_control_name=@bgm_sys_control_name";

				dbManager.Open();
				 dtb = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0];
				dbManager.Dispose(); 
				return Convert.ToInt32(dtb.Rows[0][0]);
			}
			catch (Exception error)
			{
				return -1;
			}
        }

        public static string _ConnectionString
        {
            get
            {
                return connectionString;
            }
        }

        public static DataProvider _DataProvider
        {
            get
            {
                return provider;
            }
        }

        public static string _DeleteRecordStatus
        {
            get
            {
                return deleteRecordStatus;
            }
        }

        public static string _ProcessRecordStatus
        {
            get
            {
                return processRecordStatus;
            }
        }

        public static string _ApproveRecordStatus
        {
            get
            {
                return approveRecordStatus;
            }
        }

        public static string _CancelRecordStatus
        {
            get
            {
                return cancelRecordStatus;
            }
        }

        public static string _WorkRecordStatus
        {
            get
            {
                return workRecordStatus;
            }
        }

        public static string _ActiveRecordStatus
        {
            get
            {
                return activeRecordStatus;
            }
        }

        public static int _CurrentYear
        {
            get
            {
                return currentYear;
            }
        }
        public static int _CurrentYearReq
        {
            get
            {
                if(currentYearReq == -1)
                    GetCurrentYearRequest();

                return currentYearReq;
            }
        }
        public static string _RejectStatus
        {
            get
            {
                return rejectStatus;
            }
        }
    }
}
